package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.AdminOrderServiceImpl;
import com.sky.service.impl.OrderServiceImpl;
import com.sky.vo.OrderDetailsVO;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController("adminOrderController")
@Slf4j
@RequestMapping("/admin/order")
@Api(tags = "订单模块")
public class OrderController {
    @Autowired
    private AdminOrderServiceImpl adminOrderService;
    @Autowired
    private OrderServiceImpl orderService;
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        log.info("{}",dto);
        adminOrderService.confirm(dto.getId().intValue());
        return Result.success();
    }

    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result reject(@RequestBody OrdersRejectionDTO dto){
        adminOrderService.reject(dto);
        return Result.success();
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result getdetails(@PathVariable String id){
        OrderDetailsVO result = adminOrderService.getdetails(id);
        return Result.success(result);
    }

    @ApiOperation("订单取消")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        adminOrderService.cancel(dto);
        return Result.success();
    }

    @ApiOperation("订单条件查询")
    @GetMapping("/conditionSearch")
    public Result search(OrdersPageQueryDTO dto){
        PageResult result = adminOrderService.search(dto);
        return Result.success(result);
    }

    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable String id){
        adminOrderService.complete(id);
        return Result.success();
    }

    @ApiOperation("查询各种状态订单")
    @GetMapping("/statistics")
    public Result statistics(){
        OrderStatisticsVO vo = adminOrderService.get();
        return Result.success(vo);
    }

    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable String id){
        adminOrderService.delivery(id);
        return Result.success();
    }
}
